package se.sweco.gpsservice.datatypes;

public class GPSDataGPGLL {
	float Latitude = 0.0f;
	String LatitudeType = "";
	float Longitude = 0.0f;
	String LongitudeType = "";
	String time = "";
	String valid = "";
	String CheckSum = "";
	
	public void parseData(String data) {
		String[] gpsData = data.split(",");
		String gpsDataType = gpsData[0].substring(1);
		
		if(gpsDataType.equals("GPGLL")) {
			if(!gpsData[1].trim().equals(""))
				Latitude = new Float(gpsData[1]).floatValue();
			if(!gpsData[2].trim().equals(""))
				LatitudeType = gpsData[2];
			if(!gpsData[3].trim().equals(""))
				Longitude = new Float(gpsData[3]).floatValue();
			if(!gpsData[4].trim().equals(""))
				LongitudeType = gpsData[4];
			if(!gpsData[5].trim().equals(""))
				time = gpsData[5];
			if(!gpsData[6].trim().equals(""))
				valid = gpsData[6];
			if(!gpsData[7].trim().equals(""))
				CheckSum = gpsData[7];
		}
	}
	
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("Latitude: " + this.Latitude + " (" + this.LatitudeType + ")" + "\n");
		sb.append("Longitude: " + this.Longitude + " (" + this.LongitudeType + ")" + "\n");
		sb.append("Time: " + this.time + "\n");
		sb.append("Valid: ");
		if(valid.equals("A")) sb.append(" OK" + "\n");
		if(valid.equals("V")) sb.append(" Void" + "\n");
		return sb.toString();
	}
	
	public float getLatitude() {
		return Latitude;
	}
	public void setLatitude(float latitude) {
		Latitude = latitude;
	}
	public String getLatitudeType() {
		return LatitudeType;
	}
	public void setLatitudeType(String latitudeType) {
		LatitudeType = latitudeType;
	}
	public float getLongitude() {
		return Longitude;
	}
	public void setLongitude(float longitude) {
		Longitude = longitude;
	}
	public String getLongitudeType() {
		return LongitudeType;
	}
	public void setLongitudeType(String longitudeType) {
		LongitudeType = longitudeType;
	}
	public String getTime() {
		return time;
	}
	public void setTime(String time) {
		this.time = time;
	}
	public String getValid() {
		return valid;
	}
	public void setValid(String valid) {
		this.valid = valid;
	}
	public String getCheckSum() {
		return CheckSum;
	}
	public void setCheckSum(String checkSum) {
		CheckSum = checkSum;
	}
}
